<template>
  <div>
    <h3>Persion 组件 </h3>
    <span v-show="serveStr">{{serveStr}}</span>
    <h4>上方组件求和为 {{sum}}</h4>
    <h4>首个人名 {{firstName}}</h4>
    <input type="text" placeholder="输入姓名" v-model="inputName">
    <button @click="add">添加</button>
    <button @click="add_wang">添加名字含王的人</button>
    <ul>
      <li v-for="item in persions" :key="item.id">{{item.name}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name:'Persion',
  data() {
    return {
      inputName:'',
      str:''
    }
  },
  computed:{
    persions() {
      return this.$store.state.persionAbout.persionList
    },
    sum() {
      return this.$store.state.countAbout.sum
    },
    firstName() {
      return this.$store.getters['persionAbout/firstName']
    },
    serveStr() {
      return this.$store.state.persionAbout.serverStr
    },
  },
  methods: {
    add() {
      this.$store.commit('persionAbout/ADD_PERSION',{id:Date.now()+'_persion',name:this.inputName})
    },
    add_wang() {
      this.$store.dispatch('persionAbout/addWang',{id:Date.now()+'_persion',name:this.inputName})
    }  
  },
  mounted() {
    this.$store.dispatch('persionAbout/addForServe',{})
  }
}
</script>

<style>

</style>